Page({
  data: {
    //下面是字母排序
    letter: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"],
    cityListId: '',
    //下面是城市列表信息，这里只是模拟数据
    citylist: [
      { "letter": "A", "data": [{ "id": "340000", "cityName": "安徽" }] }, 
      { "letter": "B", "data": [{ "id": "511900", "cityName": "巴中" }, { "id": "150200", "cityName": "包头" }, { "id": "110000", "cityName": "北京" }] }, 
      { "letter": "C", "data": [{ "id": "510100", "cityName": "成都" }] }, 
      { "letter": "D", "data": [{ "id": "513337", "cityName": "稻城" }] }, 
      { "letter": "G", "data": [{ "id": "440100", "cityName": "广州" }, { "id": "450300", "cityName": "桂林" }] },
       { "letter": "H", "data": [{ "id": "460000", "cityName": "海南" }, { "id": "330100", "cityName": "杭州" }, { "id": "150100", "cityName": "呼和浩特" }] }, 
       { "letter": "L", "data": [{ "id": "410300", "cityName": "洛阳" }, { "id": "540100", "cityName": "拉萨" }, { "id": "530700", "cityName": "丽江" }] }, 
       { "letter": "M", "data": [{ "id": "511400", "cityName": "眉山" },{"id": "510700", "cityName": "绵阳市"}] }, 
       { "letter": "N", "data": [{ "id": "320100", "cityName": "南京" },{"id": "511300", "cityName": "南充"}] }, 
       { "letter": "S", "data": [{ "id": "460200", "cityName": "三亚" }, { "id": "440300", "cityName": "深圳" }, { "id": "310000", "cityName": "上海" }] }, { "letter": "T", "data": [{ "id": "120000", "cityName": "天津" }] }, { "letter": "W", "data": [{ "id": "650100", "cityName": "乌鲁木齐" }, { "id": "420100", "cityName": "武汉" }] }, { "letter": "X", "data": [{ "id": "610100", "cityName": "西安" }, { "id": "810000", "cityName": "香港" }, { "id": "350200", "cityName": "厦门" }] }, { "letter": "Z", "data": [{ "id": "130700", "cityName": "张家口" }] }],
    //下面是热门城市数据，模拟数据
    newcity: ['北京', '上海', '广州', '深圳', '成都', '杭州'],
    newcitys:[
      { "id": "110000", "cityName": "北京" },
      { "id": "310000", "cityName": "上海" },
      { "id": "440100", "cityName": "广州" },
      { "id": "440300", "cityName": "深圳" },
      { "id": "330100", "cityName": "杭州" },
      { "id": "510100", "cityName": "成都" },

    ],
    // citySel: '全国',
    locateCity: ''
  },

  //热门城市
  cityHot(e){

    let objCity=e.currentTarget.dataset.val
    
    let pages = getCurrentPages();
    
    let prevPage = pages[pages.length - 2]; //上一个页面
    prevPage.setData({
      mydata: {
        cid:objCity.id,
        city:objCity.cityName,
     
        
      }
    })
    wx.navigateBack({//返回
      delta: 1
    })
  },

    //点击城市
    cityTap (e) {
      console.log(e)
      let  val = e.currentTarget.dataset.val || ''
      let types = e.currentTarget.dataset.types || ''
      let  Index = e.currentTarget.dataset.index || ''
      
        let objCity= e.currentTarget.dataset.val
        // that = this;
      let city = this.data.citySel;
      
      switch (types) {
        case 'locate':
          //定位内容
          city = this.data.locateCity;
          break;
        case 'national':
          //全国
          city = '全国';
          break;
        case 'new':
          //热门城市
          city = val;
          break;
        case 'list':
          //城市列表
          city = val.cityName;
          break;
      }
      if (city) {
        wx.setStorage({
          key: 'city',
          data: city
        })
        　　　　//点击后给父组件可以通过bindcitytap事件，获取到cityname的值，这是子组件给父组件传值和触发事件的方法
        this.triggerEvent('citytap', { cityname: city });
      } else {
        console.log('还没有');
        this.getLocate();
      }
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2]; //上一个页面
      prevPage.setData({
        mydata: {
          cid:objCity.id,
          city:objCity.cityName,
       
          
        }
      })
      wx.navigateBack({//返回
        delta: 1
      })

    },
    //点击城市字母
    letterTap(e) {
      const Item = e.currentTarget.dataset.item;
      this.setData({
        cityListId: Item
      });
    },
})